package com.sudo.service.tldata;

import com.sudo.common.enums.SysJobType;
import com.sudo.dao.admin.entity.SysMethodJob;
import com.sudo.dao.admin.entity.SysServerNodeJob;
import com.sudo.service.admin.runnable.BeanMethodRunnable;
import com.sudo.service.admin.runnable.RpcMethodRunnable;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

public class ThreadLocalObject {

    public static Map<String,Object> initJobConfigMap(SysMethodJob sysMethodJob) {
        Map<String, Object> jobConfigMap = new HashMap<>();
        jobConfigMap.put("tl_jobId", sysMethodJob.getId());
        jobConfigMap.put("tl_jobBean", sysMethodJob.getBeanName());
        jobConfigMap.put("tl_jobMethod", sysMethodJob.getMethodName());
        jobConfigMap.put("tl_jobParams", sysMethodJob.getMethodParams());
        jobConfigMap.put("tl_logStatus", sysMethodJob.getLogStatus());
        jobConfigMap.put("tl_mailStatus", sysMethodJob.getMailStatus());
        jobConfigMap.put("tl_mailAddress", sysMethodJob.getMailAddress());
        jobConfigMap.put("tl_jobStartTime", LocalDateTime.now());
        jobConfigMap.put("tl_jobType", SysJobType.LOCAL.name());
        return jobConfigMap;
    }

    public static Map<String,Object> initJobConfigMap(BeanMethodRunnable beanMethodRunnable) {
        Map<String, Object> jobConfigMap = new HashMap<>();
        jobConfigMap.put("tl_jobId", beanMethodRunnable.getId());
        jobConfigMap.put("tl_jobBean", beanMethodRunnable.getBeanName());
        jobConfigMap.put("tl_jobMethod", beanMethodRunnable.getMethodName());
        jobConfigMap.put("tl_jobParams", beanMethodRunnable.getParams());
        jobConfigMap.put("tl_logStatus", beanMethodRunnable.getLogStatus());
        jobConfigMap.put("tl_mailStatus", beanMethodRunnable.getMailStatus());
        jobConfigMap.put("tl_mailAddress", beanMethodRunnable.getMailAddress());
        jobConfigMap.put("tl_jobStartTime", LocalDateTime.now());
        jobConfigMap.put("tl_jobType", SysJobType.LOCAL.name());
        return jobConfigMap;
    }

    public static Map<String,Object> initJobConfigMap(SysServerNodeJob sysServerNodeJob) {
        Map<String, Object> jobConfigMap = new HashMap<>();
        jobConfigMap.put("tl_jobId", sysServerNodeJob.getId());
        jobConfigMap.put("tl_jobServer", sysServerNodeJob.getServer());
        jobConfigMap.put("tl_jobBean", sysServerNodeJob.getBeanName());
        jobConfigMap.put("tl_jobMethod", sysServerNodeJob.getMethodName());
        jobConfigMap.put("tl_jobParams", sysServerNodeJob.getMethodParams());
        jobConfigMap.put("tl_logStatus", sysServerNodeJob.getLogStatus());
        jobConfigMap.put("tl_mailStatus", sysServerNodeJob.getMailStatus());
        jobConfigMap.put("tl_mailAddress", sysServerNodeJob.getMailAddress());
        jobConfigMap.put("tl_jobStartTime", LocalDateTime.now());
        jobConfigMap.put("tl_jobType", SysJobType.REMOTE.name());
        return jobConfigMap;
    }

    public static Map<String,Object> initJobConfigMap(RpcMethodRunnable rpcMethodRunnable) {
        Map<String, Object> jobConfigMap = new HashMap<>();
        jobConfigMap.put("tl_jobId", rpcMethodRunnable.getId());
        jobConfigMap.put("tl_jobServer", rpcMethodRunnable.getServer());
        jobConfigMap.put("tl_jobBean", rpcMethodRunnable.getBeanName());
        jobConfigMap.put("tl_jobMethod", rpcMethodRunnable.getMethodName());
        jobConfigMap.put("tl_jobParams", rpcMethodRunnable.getParams());
        jobConfigMap.put("tl_logStatus", rpcMethodRunnable.getLogStatus());
        jobConfigMap.put("tl_mailStatus", rpcMethodRunnable.getMailStatus());
        jobConfigMap.put("tl_mailAddress", rpcMethodRunnable.getMailAddress());
        jobConfigMap.put("tl_jobStartTime", LocalDateTime.now());
        jobConfigMap.put("tl_jobType", SysJobType.REMOTE.name());
        return jobConfigMap;
    }
}
